package com.thd.springboottest.mybatisplus.config;

import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.thd.springboottest.mybatisplus.interceptor.MybatisPlusPrintSqlInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * com.thd.springboottest.mybatisplus.config.MybatisPlusConfig
 * mybatis plus 插件配置类
 * @author: wanglei62
 * @DATE: 2019/9/20 17:09
 **/

@EnableTransactionManagement
@Configuration
/**
 * 下面的配置都可以 * 匹配1个任意包名  ** 匹配1个或多个包名
 * 如果配置多个包@MapperScan({"com.thd.**.mapper","com.thd.mybatis.*.mapper"})
 */
//@MapperScan("com.thd.springboottest.mybatisplus.mapper")
//@MapperScan("com.thd.**.mapper")
@MapperScan("com.thd.springboottest.*.mapper")

public class MybatisPlusConfig {
    /**
     * 3.2.0版starter 分页插件
     */
    /*
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // paginationInterceptor.setLimit(你的最大单页限制数量，默认 500 条，小于 0 如 -1 不受限制);
        return paginationInterceptor;
    }
*/



    /**
     * 3.5.3版starter 分页插件
     * @return
     */
/*
    @Bean
    public PaginationInnerInterceptor mybatisPlusInterceptor(){

        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        // 设置请求的页面大于最大页后操作， true调回到首页，false 继续请求  默认false
        paginationInnerInterceptor.setOverflow(false);
        //设置最大单页限制数量，默认 500 条，-1 最大999条
        paginationInnerInterceptor.setMaxLimit(-1L);
        return paginationInnerInterceptor;
    }*/
    @Bean
    public MybatisPlusInterceptor paginationInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        // 设置请求的页面大于最大页后操作， true调回到首页，false 继续请求  默认false
        paginationInnerInterceptor.setOverflow(false);
        //设置最大单页限制数量，默认 500 条，-1 最大999条
        paginationInnerInterceptor.setMaxLimit(-1L);
        mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
        return mybatisPlusInterceptor;
    }




    /**
     * 打印SQL
     * @return
     */
    @Bean
    public MybatisPlusPrintSqlInterceptor mybatisSQLInterceptor() {
        return new MybatisPlusPrintSqlInterceptor(false);
    }


//    /**
//     * 逻辑删除
//     * @return
//     */
//    @Bean
//    public ISqlInjector sqlInjector(){
//        return new DefaultSqlInjector();
//    }

}
